/*
 * Copyrignt (c) xuzeshui.com. All Rights Reserved.
 * Author: Zeshui Xu<i@xuzeshui.com>
 * Created Time: 2015-09-29 20:11:44
 * Last Modified: 2016-11-28 21:55:29
 * File Name: db/iminfo.go
 * Description:
 */
package db

import (
	//"fmt"

	"doubimeizhi.com/utility"

	"github.com/astaxie/beego"
)

var (
	mySQLHelper *utility.MySQLHelper
)

func createMySQLHelper() bool {
	mysqlHost := beego.AppConfig.DefaultString("qkstatis::mysql_host", "127.0.0.1")
	mysqlPort := beego.AppConfig.DefaultInt("qkstatis::mysql_port", 4100)
	mysqlUser := beego.AppConfig.DefaultString("qkstatis::mysql_user", "root")
	mysqlPass := beego.AppConfig.DefaultString("qkstatis::mysql_password", "")
	mysqlDB := beego.AppConfig.DefaultString("qkstatis::mysql_db", "qingke")
	maxOpenConns := beego.AppConfig.DefaultInt("qkstatis::mysql_maxOpenConns", 10)
	maxIdleConns := beego.AppConfig.DefaultInt("qkstatis::mysql_maxIdleConns", 5)
	mySQLHelper = utility.NewMySQLHelper(mysqlHost, mysqlPort, mysqlUser, mysqlPass, mysqlDB, maxOpenConns, maxIdleConns)
	return true
}

func GetMySQLHelper() *utility.MySQLHelper {
	if mySQLHelper == nil {
		createMySQLHelper()
	}
	return mySQLHelper
}

func init() {
	GetMySQLHelper()
}
